#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int d[N], d2[N];
int lowbit(int x) { return x & -x; }
void update(int x, int v) {
  for (int i = x; i <= n; i += lowbit(i)) d[i] += v;
}
int query(int x) {
  int res = 0;
  for (int i = x; i > 0; i -= lowbit(i)) res += d[i];
  return res;
}
void update2(int x, int v) {
  for (int i = x; i <= n; i += lowbit(i)) d2[i] += v;
}
int query2(int x) {
  int res = 0;
  for (int i = x; i > 0; i -= lowbit(i)) res += d2[i];
  return res;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  while (m--) {
    int op, l, r;
    cin >> op >> l >> r;
    if (op == 1) {
      update(l, 1), update(r + 1, -1);
      update2(l, 1);
    } else {
      int x = query(l);
      int y = query2(r) - query2(l);
      cout << x + y << endl;
    }
  }
  return 0;
}